#coding= UTF-8

offset_x = 100
offset_y = 20
stretch = 50

def Element(element):

    def wrapper(brush, *args):
        
        e = element(*args)

        draw = e.draw
        
        def draw_func(dc):
            dc.SetBrush(brush)
            draw(dc)
        e.draw = draw_func
        
        return e

    return wrapper

@Element
class board(object):

    def __init__(self, N=15, M=15):
        self.N = N
        self.M = M

    def draw(self, dc):
        for x in range(self.N):
            pos_x = offset_x + x * stretch
            pos_y_start = offset_y
            pos_y_end = offset_y + (self.M-1) * stretch
            dc.DrawLine(pos_x, pos_y_start, pos_x, pos_y_end)

        for y in range(self.M):
            pos_y = offset_y + y * stretch
            pos_x_start = offset_x
            pos_x_end = offset_x + (self.N-1) * stretch
            dc.DrawLine(pos_x_start, pos_y, pos_x_end, pos_y)

        dc.DrawCircle(offset_x+self.N//2*stretch, offset_y+self.M//2*stretch, 5)

    def catch(self, pos_x, pos_y):
        x = pos_x-offset_x+stretch//2
        y = pos_y-offset_y+stretch//2
        print(x%stretch, y%stretch)
        # 最低限度的避免落子位置模糊
        if not(1 < x%stretch < 49) or not(1 < y%stretch < 49): return -1, -1
        return x//stretch, y//stretch

@Element
class atom(object):

    def __init__(self, x, y):
        self.r = 20
        self.x = offset_x + x * stretch
        self.y = offset_y + y * stretch

    def draw(self, dc):
        dc.DrawCircle(self.x, self.y, self.r)

@Element
class last(object):

    def __init__(self):
        self.x = None
        self.y = None
        self.e = stretch//2
        self.d = stretch//4

    def at(self, x, y):
        self.x = x
        self.y = y

    def draw(self, dc):
        if self.x == None or self.y == None:
            return
        x = offset_x + self.x * stretch
        y = offset_y + self.y * stretch

        dc.DrawLine(x-self.e, y-self.e, x-self.d, y-self.e)
        dc.DrawLine(x+self.d, y-self.e, x+self.e, y-self.e)
        dc.DrawLine(x-self.e, y+self.e, x-self.d, y+self.e)
        dc.DrawLine(x+self.d, y+self.e, x+self.e, y+self.e)

        dc.DrawLine(x-self.e, y-self.d, x-self.e, y-self.e)
        dc.DrawLine(x+self.e, y-self.d, x+self.e, y-self.e)
        dc.DrawLine(x-self.e, y+self.d, x-self.e, y+self.e)
        dc.DrawLine(x+self.e, y+self.d, x+self.e, y+self.e)


# class element(object):

#     def __init__(self, dc, brush):
#         offset = {"x":100, "y":20}
#         stretch = 50
#         self.dc = dc
#         self.b = brush

#     def draw(self):
#         self.dc.setBrush(self.b)

#     @abstractmethod
#     def click(self, dc):
#         raise("not implement")